package ocean.chinacraft.common.world.gen;

import net.minecraft.util.RegistryKey;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.Features;
import net.minecraft.world.gen.placement.AtSurfaceWithExtraConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import ocean.chinacraft.common.world.gen.features.ModConfiguredFeatures;

import java.util.List;
import java.util.Set;
import java.util.function.Supplier;

/**
 * 桑树生成
 *
 * @author zhang
 * @since 2021/11/30
 */
public class ModTreeGeneration {

    public static void generateTrees(final BiomeLoadingEvent event) {
        if (event.getName() != null) {
            RegistryKey<Biome> key = RegistryKey.create(Registry.BIOME_REGISTRY, event.getName());
            Set<BiomeDictionary.Type> types = BiomeDictionary.getTypes(key);

            if (types.contains(BiomeDictionary.Type.FOREST)) {
                List<Supplier<ConfiguredFeature<?, ?>>> base =
                        event.getGeneration().getFeatures(GenerationStage.Decoration.VEGETAL_DECORATION);

                base.add(() -> ModConfiguredFeatures.MULBERRY_TREE
                        .decorated(Features.Placements.HEIGHTMAP_SQUARE)
                        .decorated(Placement.COUNT_EXTRA.configured(
                                new AtSurfaceWithExtraConfig(1, 0.25f, 2))));
            }
        }
    }
}
